package com.example.votingsystem.repository;

import com.example.votingsystem.entity.VoteTopic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
import java.util.List;

public interface VoteTopicRepository extends JpaRepository<VoteTopic, Long> {
    List<VoteTopic> findByIsActiveTrue();
    
    @Query("SELECT v FROM VoteTopic v WHERE v.endTime > ?1 AND v.isActive = true ORDER BY v.endTime ASC")
    List<VoteTopic> findUpcomingVotes(LocalDateTime now);
    
    @Query("SELECT v FROM VoteTopic v WHERE v.isActive = true ORDER BY SIZE(v.voteOptions) DESC")
    List<VoteTopic> findPopularVotes();
}
